package com.example.studentalarm.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;

import com.example.studentalarm.R;
import com.example.studentalarm.presenter.BasePresenter;
import com.example.studentalarm.widget.statuslayout.StateLayout;


/***
 * 列表页面模型
 * */
public abstract class ListPageModelActivity<V, T extends BasePresenter<V>> extends BaseModelActivity<V, T> {

    public abstract StateLayout.Builder getBuilderLayout();

    protected StateLayout rootView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        if (getBuilderLayout() != null && isFirstInit) {
            rootView = getBuilderLayout().build();
            FrameLayout frameLayout = findViewById(R.id.fragment_layout_container);
            if (frameLayout != null) {
                frameLayout.addView(rootView);
            }
        }
    }

    /**
     * @param view
     */
    public void showRootView(View view) {
        rootView.setVisibility(View.VISIBLE);
        view.setVisibility(View.GONE);
    }

    /**
     * @param view
     */
    public void hideRootView(View view) {
        rootView.setVisibility(View.GONE);
        view.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (rootView != null) {
            rootView.unBindListener();
        }
    }
}
